package com.songcan.oauth.provider;

import com.songcan.oauth.compent.OauthUserDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component("preAuthProvider")
public class CustomPreAuthProvider  extends PreAuthenticatedAuthenticationProvider {

    private OauthUserDetailsService oauthUserDetailsService;

    @Autowired
    public CustomPreAuthProvider(OauthUserDetailsService oauthUserDetailsService){
        this.oauthUserDetailsService = oauthUserDetailsService;
    }


    public CustomPreAuthProvider(){
        super();
    }

    @PostConstruct
    public void init(){
        super.setPreAuthenticatedUserDetailsService(new UserDetailsByNameServiceWrapper(oauthUserDetailsService));

    }
}
